

public class ShowingRow {
	private String cName;
	private String title;
	private String genre;
	private String rating;
	private int time;
	public static boolean edit_admin = false;

	public ShowingRow(String the_cName, String the_title, int the_time) {
		cName = the_cName;
		title = the_title;
		time = the_time;
	}

	/**
	 * Takes a string of data (returned from the database) to construct this
	 * object.
	 * @param the_data The row to be converted.
	 */
	public ShowingRow(String the_data) {
		parseDataString(the_data);
	}

	public void set(String the_data) {
		parseDataString(the_data);
	}

	public String getCName() { return cName; }
	public String getTitle() { return title; }
	public String getGenre() { return genre; }
	public String getRating(){ return rating;}
	public int 	  getTime()  { return time;  }

	public String[] getDataArray() {
		String[] arr = new String[3];
		arr[0] = cName;
		arr[1] = title;
		arr[2] = getTimeString();
		return arr;
	}

	/**
	 * Converts the integer time into a human readable time.
	 * @return the object's time in HH:MM PM format.
	 */
	public String getTimeString() {
		int hours = time/100;
		int minutes = time - (100 * hours);

		StringBuilder sb = new StringBuilder();

		if(0 == hours % 12)
			sb.append("12");
		else
			sb.append(String.valueOf(hours % 12));
		sb.append(":");
		if(10 > minutes)
			sb.append('0');
		sb.append(String.valueOf(minutes));

		sb.append(" ");
		sb.append(0 < (hours / 12) ? "PM" : "AM");

		return sb.toString();
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(cName);
		sb.append("\t");
		sb.append(title);
		sb.append("\t");
		sb.append(genre);
		sb.append("\t");
		sb.append(rating);
		sb.append("\t");
		sb.append(getTimeString());
		return sb.toString();
	}


	private void parseDataString(String str) {
		if (!edit_admin) {
			cName = str.substring(0,str.indexOf('\t')).trim();
			str = str.substring(str.indexOf('\t'),str.length()).trim();
		}

		title = str.substring(0,str.indexOf('\t')).trim();
		str = str.substring(str.indexOf('\t'),str.length()).trim();

		if (!edit_admin) {
			genre = str.substring(0,str.indexOf('\t')).trim();
			str = str.substring(str.indexOf('\t'),str.length()).trim();

			rating = str.substring(0,str.indexOf('\t')).trim();
			str = str.substring(str.indexOf('\t'),str.length()).trim();
		}

		time = Integer.parseInt(str);
	}
}
